// 免费停车场记录加载
window.onload = function () {
    var url = 'http://192.168.0.106:8080/AppPark/getAllAppParkByPage'
    function s(datas) {
        function operateFormatter(value, row, index) {//赋予的参数
            return [
                "<button  class='btn btn-primary' style='margin-right:10px' onclick=detailsfree(" + row.parkid + ")>详情</button>"
            ].join('');
        }
        // 设置table列样式
        function formatFormatter(value, row, index) {
            if (value == 1) {
                return [
                    '<span>收费</span>',
                ].join('');
            } else {
                return [
                    '<span>免费</span>',
                ].join('');
            }
        }
        // 停车场
        function formatFormatterP(value, row, index) {
            if (value == 1){
               
                    return [
                        '<span>室内</span>',
                    ].join('');
                   
                }else if(value == 2){
                    return [
                        '<span>室外</span>',
                    ].join('');
                   
                }else if(value == 3){
                    return [
                        '<span>路边</span>',
                    ].join('');
                 
            }
        }
        // 状态
        function  formatFormatterStatu(value, row, index) {
            if (value == 1){
            
            return [
               
                '<img src="../../../images/success.png" onclick="statusChange(' + row.validflag+','+row.cityid + ')">',
            ].join('');
        }else{
            return [
               
                '<img src="../../../images/fail.png" onclick="statusChange(' + row.validflag +','+row.cityid + ')">',
            ].join('');
        }
        }
        var tableColumns = [
            {
                field: 'parkid',
                title: 'ID',
                switchable: true
            }, {
                field: 'name',
                title: '名称',
                switchable: true
            },
            {
                field: 'address',
                title: '地址',
                switchable: true
            },
            {
                field: 'parktypeid',
                title: '停车场类型',
                formatter:formatFormatterP
            },
            {
                field: 'isshoufeiflag',
                title: '是否收费',
                formatter: formatFormatter
            },
            {
                field: 'isownaddflag',
                title: '状态',
                formatter: formatFormatterStatu
            }, {
                field: 'operate',
                title: '操作',
                formatter: operateFormatter //自定义方法，添加操作按钮
            }
        ];
        $("#onlinetable").bootstrapTable('destroy'); //分页必须写
        $("#onlinetable").bootstrapTable({
            cache: false,
            pagination: true,
            sidePagination: "client",  //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,   //初始化加载第一页，默认第一页
            pageSize: 5,   //每页的记录行数（*）
            pageList: [5, 10], //可供选择的每页的行数
            columns: tableColumns,
            data: datas,
            queryParamsType: '',
            //得到查询的参数
            queryParams: function queryParams(params) {
                return params;
            },
            onLoadSuccess: function (data) {  //加载成功时执行
                alert("成功" + data)
            },
            onLoadError: function () {  //加载失败时执行
                alert("失败")
            }

        });
    }
    $.ajax({
        url: url,
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        success: function (res) {
            console.log(res.data)
            s(res.data)
        }
    })
//    赋值给下拉列表
$.ajax({
    url: "http://192.168.0.106:8080/AppPark/getCityAndArea",
    method: 'post',
    contentType: "application/x-www-form-urlencoded",
    data:{
        typeId:1,
    },
    success: function (res) {
        console.log(res.data)

        var typecity = res.data
        var citys ;
        for(var i=0;i<typecity.length;i++){
            console.log(typecity[i].name)
             citys = typecity[i]
             $("#firstcity").append("<option id='citys' value='" + citys.cityid+"'>" + citys.name+  "</option>"); //动态放入所需的值
               // $("#agency").append("<option value='" + citys.merchantName+ "'>" + citys.merchantName+  "</option>");
        }
       
    }
})
}
$(document).bind('change', '.selectcity', function(e){
    var options=$("#firstcity option:selected").val();
    console.log(options)
    $.ajax({
        url: "http://192.168.0.106:8080/AppPark/getCityAndArea",
        method: 'post',
        contentType: "application/x-www-form-urlencoded",
        data:{
            typeId:2,
            cityid:options,
        },
        success: function (res) {
            console.log(res.data)
    
            var typecity = res.data
            var citys ;
            $("#areancy").empty();
            for(var i=0;i<typecity.length;i++){
                console.log(typecity[i].name)
                 citys = typecity[i]
                 $("#areancy").append("<option value='" + citys.areaid+ "'>" + citys.name+  "</option>");
            }
           
        }
    })
}) 
function change() {
    var x = document.getElementById("first");
    var y = document.getElementById("second");
    y.options.length = 0; // 清除second下拉框的所有内容 
    if (x.selectedIndex == 0) {
        y.options.add(new Option("黄冈", "0"));
        y.options.add(new Option("武汉", "1", false, true));  // 默认选中省会城市  
    } if (x.selectedIndex == 1) {
        y.options.add(new Option("深圳", "0"));
        y.options.add(new Option("广州", "1", false, true));  // 默认选中省会城市	
        y.options.add(new Option("肇庆", "2"));
    }
}
function changeCity() {
    var x = document.getElementById("firstcity");
    var y = document.getElementById("secondcity");
    y.options.length = 0; // 清除second下拉框的所有内容 
    if (x.selectedIndex == 0) {
        y.options.add(new Option("柳北区", "0"));
        y.options.add(new Option("鱼峰区", "1", false, true));  // 默认选中省会城市  
    } if (x.selectedIndex == 1) {
        y.options.add(new Option("青秀区", "0"));
        y.options.add(new Option("西塘区", "1", false, true));  // 默认选中省会城市	
        y.options.add(new Option("高新区", "2"));
    }
}
function backonline(e) {
    // 返回
    divset = document.getElementsByClassName("search");
    for (var i = 0; i < divset.length; i++) {
        divset[i].style.display = "inline";
    };
    divsetadd = document.getElementsByClassName("detailsonline");
    for (var i = 0; i < divset.length; i++) {
        divsetadd[i].style.display = "none";
    };
    divsetadd = document.getElementsByClassName("editonline");
    for (var i = 0; i < divset.length; i++) {
        divsetadd[i].style.display = "none";
    };
    divsetadd = document.getElementsByClassName("addonline");
    for (var i = 0; i < divset.length; i++) {
        divsetadd[i].style.display = "none";
    };
}
function detailsonline(e) {
    // 详情
    divset = document.getElementsByClassName("search");
    for (var i = 0; i < divset.length; i++) {
        divset[i].style.display = "none";
    };
    divsetedit = document.getElementsByClassName("detailsonline");
    for (var i = 0; i < divset.length; i++) {
        divsetedit[i].style.display = "inline";
    };
}
function addonline(e) {
    // 添加
    divset = document.getElementsByClassName("search");
    for (var i = 0; i < divset.length; i++) {
        divset[i].style.display = "none";
    };
    divsetedit = document.getElementsByClassName("addonline");
    for (var i = 0; i < divset.length; i++) {
        divsetedit[i].style.display = "inline";
    };
}
function editonline(e) {
    // 编辑
    divset = document.getElementsByClassName("search");
    for (var i = 0; i < divset.length; i++) {
        divset[i].style.display = "none";
    };
    divsetedit = document.getElementsByClassName("editonline");
    for (var i = 0; i < divset.length; i++) {
        divsetedit[i].style.display = "inline";
    };
}
// 切换状态
function changeStata(e) {
    var Img = document.getElementById('img');
    $('#myModal').modal('hide');
    if (Img.getAttribute("src", 2) == '../../../images/success.png') {
        Img.setAttribute("src", "../../../images/fail.png");
        $('#modal-input').html('确认启用');
    } else {
        Img.setAttribute("src", '../../../images/success.png');
        //此处即为修改modal的标题
        $('#modal-input').html('确认停用');
    }
}